package com.eastfair.home.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeServiceLossService;
import com.eastfair.venuebooking.api.ServiceLossFeign;
import com.eastfair.venueservice.dto.ServiceLossDTO;
import com.eastfair.venueservice.vo.ServiceLossVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 物资报损 service.
 *
 * @author dqq
 * @date 2022 /9/22
 */
@Service
@Slf4j
public class HomeServiceLossServiceImpl implements HomeServiceLossService {

    @Resource
    private ServiceLossFeign serviceLossFeign;

    @Override
    public Page<ServiceLossVO> queryServiceLoss(PageParams<ServiceLossDTO> pageParams) {
        log.info("queryServiceLoss - 分页查询报损记录VO列表, pageParams={}", pageParams);
        R<Page<ServiceLossVO>> result = serviceLossFeign.queryServiceLoss(pageParams);
        log.info("queryServiceLoss - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean repairInInventory(ServiceLossDTO serviceLossDTO) {
        log.info("repairInInventory - 返修入库, serviceLossDTO={}", serviceLossDTO);
        R<Boolean> result = serviceLossFeign.repairInInventory(serviceLossDTO);
        log.info("repairInInventory - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public Map<String, Object> countLossNum(ServiceLossDTO serviceLossDTO) {
        log.info("countLossNum - 报损类型统计, serviceLossDTO={}", serviceLossDTO);
        R<Map<String, Object>> result = serviceLossFeign.countLossNum(serviceLossDTO);
        log.info("countLossNum - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }
}